package shape3D;     

import javafx.application.Application;
import javafx.scene.AmbientLight;
import javafx.scene.PerspectiveCamera;
import javafx.scene.PointLight;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.*;
import javafx.scene.transform.Rotate;

// 光源(都是结点)
public class LightDemo extends Application { 
	private HBox root = new HBox(50);
	private Cylinder cylinder;
	private AmbientLight al;	// 环境光(均匀光)
	private PointLight pl;		// 点光源(常用,显示立体效果)
	
	public static void main(String[] args) {
		launch(args);
	}
	
	@Override
	public void start(Stage stage) {
		
		root.setLayoutX(50);
		root.setLayoutY(100);
		
		for(int i=5; i>=1; i--) {
			cylinder = new Cylinder(30, 100);
			cylinder.setRotationAxis(Rotate.X_AXIS);
			cylinder.setRotate(30);
			root.getChildren().addAll(cylinder);
		}
		
		al = new AmbientLight(Color.ORANGE);
		al.setLightOn(false);	// 设置是否有光照射
		al.getScope().addAll(root.getChildren().get(0));	// 设置光照射的结点(默认所有结点)
//		root.getChildren().add(al);
		
		pl = new PointLight(Color.ORANGE);		// 在布局总的初始坐标和其他结点一样
		root.getChildren().add(pl);
		
		Scene scene = new Scene(root, 700, 400, true);		// 开启3D效果
		scene.setCamera(new PerspectiveCamera());		// 设置相机
		stage.setScene(scene);
		stage.show();
	}
}





